package edu.sctu.zhoumengxue.day201506.day20150623;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**获取Json解析的数据
 * Created by user12 on 2015/6/25.
 */
public class PostURL1 {

    public String getHTTPURL(String path){

        String value = "";
        byte[] bytes = new byte[1];

        try {
            URL url = new URL(path);
            try {
                URLConnection connection = url.openConnection();
                connection.connect();

                InputStream in = connection.getInputStream();
                while (( in.read(bytes))!=-1){
                    value =value + new String(bytes);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        return value;
    }

//    public String getPost(String path, String param){
//
//        int count;
//        byte[] bytes = new byte[1024];
//        try {
//            URL url = new URL(path);
//            try {
//                HttpURLConnection connection =(HttpURLConnection) url.openConnection();
//                connection.setRequestMethod("POST");
//                connection.setDoInput(true);
//                connection.setDoOutput(true);
//                connection.connect();
//
//                OutputStream out = connection.getOutputStream();
//                out.write(param.getBytes());
//                out.flush();
//
//                InputStream in = connection.getInputStream();
//                while ((count=in.read(bytes))!=-1){
//                    System.out.println(new String(bytes,0,count,"Utf-8"));
//                }
//
//
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//
//        } catch (MalformedURLException e) {
//            e.printStackTrace();
//        }
//        return path;
//    }
}
